<?php

namespace app\common;

use app\model\Question;
use app\model\QuestionAnswer;
use app\model\UsersRelated;
use think\Model;

class QuestionService
{
    /**
     * 回复
     * @param $data
     * @return QuestionAnswer|Model
     */
    static function answer($data){
        event('QuestionIncComment',$data['question_id']);//增加互动数量
        event('QuestionIncAnswer',$data['question_id']);//增加回复数量
        $help = QuestionAnswer::where(['question_id'=>$data['question_id'],'users_id'=>$data['users_id']])->find();
        if (empty($help)){
            event('UsersIncHelp',$data['users_id']);//增加帮助数量
        }
        $answer = QuestionAnswer::create($data);
        $row = Question::find($data['question_id']);
        UsersRelated::create(['users_id'=>$row->users_id,'pro_id'=>$answer->id,'type'=>5,'from_users_id'=>$data['users_id'],'scene'=>'QuestionAnswer']);
	    return $answer;
    }
}